//
//  PVDChecklistModel.swift
//  ezyform
//
//  Created by MoennigQ on 16/5/18.
//  Copyright © 2018 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import HandyJSON
//只用于Pre-Installation, mid-installation check-up, testing and commissioning checklist
//这几个checklist id在后台是固定写死的
enum ChecklistFixedId: Int32{
    case preInstall = 950
    case midInstall = 951
    case testAndCommission = 952
//    case panelModelLabel = 20
//    case inverterModelLabel = 792
//    case panelInstalled = 8
//    case inverterInstalled = 7
//    case switchBoard = 11
//    case frontOfProperty = 641
    case certificateOfElectricalSafety = 13
    //app自定义checklist id，用于共用image list的功能
    case nocAttachment = -1
    case cocAttachment = -2
    case otherAttachment = -3
    case panels = -4
    case inverters = -5
    case tanks = -6//热水器的tanks
}
class PVDChecklistModel: HandyJSON {
    var jobType : JobType = .pvdJob
    var seq_no: Int = 0//获得checklist后app这边手动添加的排列序号
    var pvdId: String = ""
    var dbId: Int32 = 0
    var id: Int32 = 0//checklist id
    var title: String = ""
    var type: String = ""
    var answer: String = ""
    var answered_at: String = ""
    var full_name: String = ""
    var is_required: String = ""
    
    var images = Array<CheckListImageDBModel>()
    //new add images
    var localAddImages = Array<CheckListImageDBModel>()
    //deleted images from server
    var localDeletedImages = Array<CheckListImageDBModel>()
    //操作actions标识
    var actions: InstallationDetailCheckListActionsModel = InstallationDetailCheckListActionsModel()
    //上传的图片是否是ESC生成的图片
    var is_app_electrician: Bool = false
    //image类型时，后台配置的需要上传的最小数量
    var minimum_quantity: Int64 = 0
    //checklist 描述
    var description: String = ""
    var is_show_photos: Bool = false
    var lodged_check: Bool = false//此值有两个用途，checklist拍照时：1.是否需要检查GPS定位是否开启，2.当前checklist是否是需要自拍
    //Pre-Installation, mid-installation check-up, testing and commissioning checklist之间的时间间隔
    var photo_interval: Int = 0
    //是否是Pre-Installation, mid-installation check-up, testing and commissioning checklist这三个checklist中的一个
    var is_selfie_flag: Bool {
        if id == ChecklistFixedId.preInstall.rawValue || id == ChecklistFixedId.midInstall.rawValue || id == ChecklistFixedId.testAndCommission.rawValue{
            return true
        }
        return false
    }
    //是否有本地数据
    var haveLocalDataFlag: Bool {
        //image类型
        if type == ChecklistType.Image.rawValue{
            if self.localDeletedImages.count > 0 {//删除的本地数据
                return true
            }else if let _ = images.firstIndex(where: {$0.oper_type == DataOperType.Add.rawValue}) {//新增的本地数据
                return true
            }
        }else{//bool或text 类型
            if oper_type == DataOperType.Add.rawValue {
                return true
            }
        }
        
        return false
    }
    //section
    var section: CheckListSectionType = .none
    var oper_type: String = "" //DataOperType的rawValue
    var localDataflag: Bool = false//用于signature中否有本地数据
    var originalChecklistFlag: Bool = true//true表示是后台配置的checklist，false表示是认为组合到checklist中的，例如：other attachment，panel，inverter ，coc，noc，panel installed
    required init(){}
}
